home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr26 / netprog.zip / NETPROG.TAR / lpr / seqno.c < prev    next >
C/C++ Source or Header  |  1989-12-17  |  546b  |  31 lines

  1. /*
  2.  * Get the sequence number to use, and update it.
  3.  */
  4.  
  5. #include    "defs.h"
  6.  
  7. int
  8. get_seqno()
  9. {
  10.     int    seqno;
  11.     FILE    *fp;
  12.  
  13.     if ( (fp = fopen(SEQNO_FILE, "r+")) == NULL)
  14.         err_sys("can't open %s", SEQNO_FILE);
  15.  
  16.     my_lock(fileno(fp));        /* exclusive lock on file */
  17.  
  18.     if (fscanf(fp, "%d", &seqno) != 1)
  19.         err_quit("fscanf error for sequence number");
  20.  
  21.     rewind(fp);
  22.     fprintf(fp, "%03d\n", (seqno+1) % 1000 );    /* next seq# to use */
  23.     fflush(fp);
  24.  
  25.     my_unlock(fileno(fp));        /* unlock file */
  26.  
  27.     fclose(fp);            /* and close it, we're done */
  28.  
  29.     return(seqno);
  30. }
  31.